package com.tubi.TreeMap;

import java.util.Comparator;
import java.util.TreeMap;

public class TreeMapDemo1 {
    public static void main(String[] args) {
        TreeMap<Student,String> tm = new TreeMap<>(new Comparator<Student>() {  //排序
            @Override
            public int compare(Student o1, Student o2) {
                int i = o1.getAge() - o2.getAge();
                i=i==0?o1.getName().compareTo(o2.getName()):i;
                return i;
            }
        });

        Student s1 = new Student("荣磊",22);
        Student s2 = new Student("磊",12);
        Student s3 = new Student("荣",12);

        tm.put(s1, "天津");
        tm.put(s2, "天");
        tm.put(s3, "津");

        tm.forEach(
                (Student key, String value)->{ 
                    System.out.println(key +"==="+ value);
                }
        );
    }
}
